home *** CD-ROM | disk | FTP | other *** search
- Path: taco.cc.ncsu.edu!bwmott
- From: bwmott@unity.ncsu.edu (Bradford Wayne Mott)
- Newsgroups: comp.lang.c++
- Subject: Virtual member functions and forward declaration
- Date: 4 Feb 1996 18:44:40 GMT
- Organization: North Carolina State University
- Message-ID: <4f2uqo$pq4@taco.cc.ncsu.edu>
- NNTP-Posting-Host: pythagoras.csc.ncsu.edu
- Keywords: virtual, member, function, g++
-
- I've got a question about forward declarations and virtual functions. My
- class layout is similar to the following:
-
- class S;
- class T;
-
- class A {
- public:
- virtual S& belong() = 0;
- };
-
- class B : public A {
- public:
- virtual T& belong() { return myT; } // This doesn't work
- private:
- T& myT;
- };
-
-
- class S {
- public:
- virtual A& get() = 0;
- };
-
- class T : public S {
- public:
- virtual B& get() { return myB; } // This works fine
- private:
- B& myB;
- };
-
- The problem I'm having is that I can redeclare the return type in one
- of the class layouts (S,T) however I can't do it in both because when
- the virtual member function [T& belong() in class B] is declared the
- compiler doesn't know that T is a subclass of S.
-
- Is there anyway to do this?
-
- Thanks,
- Bradford W. Mott
-
- P.S. I'm using g++ 2.7.2 if that makes a difference.
-
-